#!/bin/sh 

APP_PATH=out/ipcam.bin.zip
PACK_PATH=package

ECHO()
{
	echo -e "\033[32m$1\033[0m"
}

build_app()
{
	ECHO ">>>>>> build app <<<<<<"
	make -j8
}

build_pack_app()
{
	ECHO ">>>>>> build app and pack <<<<<<"

	echo -e "Please input the package version(eg:IOT_V1.01): \c"
	read VERSION
	if [ -z $VERSION ]; then
		ECHO "Input version is invalid !!!"
		exit 1
	fi
	echo $VERSION

	# build
	build_app

	# copy
	#cp ${APP_PATH}/ipcam ${PACK_PATH}/rootfs/rootfs_camera/app/bin/ -rf

	# pack
	cd ${PACK_PATH}/
	./pack.sh ${VERSION}
}

choise_build_type()
{
	echo ""
	echo "Choise Build Type:"
	echo " 1 - build" 
	echo " 2 - build and pack"
	echo ""
	echo -e "Please enter the Build Type index(default 1): \c"
	read input
	if [ -z $input ]; then
		input=1
	fi
	echo $input
	case $input in 
		1)
			build_app
			;;
		2)
			build_pack_app
			;;
	esac
}

do_main()
{
	choise_build_type
}

do_main
